package CCRMClient.Controllers;

import java.util.ArrayList;

import Common.*;
import Common.Entities.Customer;
import Common.Entities.Permission;
import Common.Entities.Regions;

/**
 * This class implements client side actions regarding customers
 * @author ori ziv
 *@author Ola
 */
public class ClientCustomerManagement {
	
	/**
	 * This method create s server request to add customer details
	 * @param command- type of command is add_customer 
	 * @param customer- all parameters of customer
	 * @return request- ServerRequest with boolean in case of add or integer in case update. 
	 */
	public static ServerRequest addCustomer (SERVER_COMMANDS command,  Customer customer) {
			
		ServerRequest request = new ServerRequest (SERVER_COMMANDS.ADD_CUSTOMER, "user");
		request.setEntity(new Customer(customer.getID(),customer.getName(),customer.getBithday(),customer.getPhone(),customer.getCustomerAddress(),customer.getCustomerStatus(),customer.getRegionID()));
		return request;
	}
	/**
	 * This method create s server request to update customer details
	 * @param command- type of command is add_UPDATE_CUSTOMER
	 * @param customer- all parameters of customer
	 * @return request- ServerRequest with boolean in case of add or integer in case update. 
	 */
	public static ServerRequest UpdateCustomer(SERVER_COMMANDS command,  Customer customer){
		ServerRequest request = new ServerRequest (SERVER_COMMANDS.UPDATE_CUSTOMER, "user");
		request.setEntity(new Customer(customer.getID(),customer.getName(),customer.getBithday(),customer.getPhone(),customer.getCustomerAddress(),customer.getCustomerStatus(),customer.getRegionID()));
		return request;
		
	}
	
	/**
	 * This method set a server request to list of regions
	 * @param command
	 * @return
	 */
	public static ServerRequest GetRegions(SERVER_COMMANDS command){
		ServerRequest request = new ServerRequest (SERVER_COMMANDS.GET_REGIONS, "user");
		return request;
		
	}
	
	
	/**
	 * This method create a server request to search customer by one of his parameters
	 * @param command
	 * @param condition
	 * @return
	 */
	public static ServerRequest SearchCustomerByCondition (SERVER_COMMANDS command, String condition) {
		ServerRequest request = new ServerRequest (SERVER_COMMANDS.GET_CUSTOMER_BY_CONDITION, "user",condition);	
		return request;
		
	}
	
	/**
	 * This method create a server request to search customer in template by templateID
	 * @param command
	 * @param tempID
	 * @return- ServerRequest with condition in SQL syntax
	 */
	public static ServerRequest showCustomersInTemplate(SERVER_COMMANDS command, int tempID){
		Integer templateID = new Integer(tempID);
		return new ServerRequest(command,"user", templateID);
	}
	
	/**
	 * this method create a server request to add a new region to the DB.
	 * @param command
	 * @param region
	 * @return ServerRequest with regions parameters
	 */
	public static ServerRequest AddRegion(SERVER_COMMANDS command, Regions region){
		ServerRequest request = new ServerRequest (SERVER_COMMANDS.ADD_REGION, "user");
		request.setEntity(new Regions(region.getRegionID(),region.getRegionName(),region.getRegionDescription()));
		return request;
		
	}
	
	  /**
	   * this method create a server request to add a new permission of customer to allow our company to call him.
	   * @param customerID
	   * @param categoryName
	   * @param permissionType
	   * @return ServerRequest with permission parameters
	   */
	public static ServerRequest addPermission(String customerID, String categoryName, int permissionType) {
		Permission prm = new Permission (permissionType, categoryName, customerID);
		return new ServerRequest(SERVER_COMMANDS.ADD_PERMISSION, null, prm);
	}
	
	/**
	 * this method create a server request to update customer status in the DB.
	 * @param command
	 * @param customerId
	 * @return ServerRequest
	 */
	public static ServerRequest UpdateCustomerStatus(SERVER_COMMANDS command, String customerId){	
		return new ServerRequest(command,"user", customerId);
	}
	
	/**
	 * This method is sending a ServerRequest for showing all the customers assigned to the salesman for a given sale  
	 * @param command
	 * @param saleAndSalesman
	 * @return server request 
	 */
	public static ServerRequest showCustomersForSalesmanInSale(SERVER_COMMANDS command, String[] saleAndSalesman){
		return new ServerRequest (command,"user", saleAndSalesman);
	}
	
	public static ServerRequest checkCustomerAvailability(SERVER_COMMANDS command, String []custID){
		return new ServerRequest (command, null, custID);
	}

}
